(function() {

    /* 01-开启严格模式 */
    "use strict";
    /* 02-声明jQuery工厂函数 */
    let jQuery = function(selector) {
        return new jQuery.prototype.init(selector);
    };

    /* 03-设置原型对象 */
    jQuery.fn = jQuery.prototype = {
        constructor: jQuery,
        get: function(param) {},
        eq: function() {},
        first: function() {},
        last: function() {},
        toArray: function() {},
        each: function() {},
        map: function() {},
        init: function(selector) {
            /* 入口函数：作用就是返回jquery实例对象 */
            /* selector == "div" */
            // console.log("selector", selector);
            /* new Person()   在函数内部会有一个this，这个this指向的是当前的实例对象*/
            if (typeof selector == "function") {
                /* 监听页面的加载 */
                document.addEventListener("DOMContentLoaded", selector);
            } else if (typeof selector == "string") {
                selector = selector.trim();
                if (selector.charAt(0) == "<" && selector.charAt(selector.length - 1) == ">" && selector.length > 3) {
                    /* 创建标签并且返回jquery对象 */
                    let temp = document.createElement("div");
                    temp.innerHTML = selector;
                    let nodes = temp.children;
                    for (let i = 0, len = nodes.length; i < len; i++) {
                        this[i] = nodes[i];
                    }
                    this.length = nodes.length;
                } else {
                    /* 获取页面中对应的标签 */
                    let items = document.querySelectorAll(selector);
                    for (let i = 0, len = items.length; i < len; i++) {
                        this[i] = items[i];
                    }
                    this.length = items.length;
                }
            }
        }
    }

    /* 04-设置原型对象共享 */
    jQuery.fn.init.prototype = jQuery.fn;

    /* 05-把jQuery暴露出去 */
    window.$ = window.jQuery = jQuery;

    /* $().css() */
    /* $().addClass() */
    /* $().removeClass() */
    /* $().show() */
    /* $().hide() */
    /* $().fadeIn() */

})();